home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH15 / EX15_3.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-03-25  |  2.0 KB  |  114 lines

  1. ; EX15_3.asm
  2. ;
  3. ; This program compares the performance of the MOVS instruction against
  4. ; a manual block move operation.  It also compares MOVS against a LODS/STOS
  5. ; loop.  This version does so in such a way as to wipe out the on-chip CPU
  6. ; cache.
  7.  
  8.         .386
  9.         option        segment:use16
  10.  
  11.         include     stdlib.a
  12.         includelib    stdlib.lib
  13.  
  14.  
  15. dseg        segment    para public 'data'
  16.  
  17. Buffer1        byte    16384 dup (0)
  18. Buffer2        byte    16384 dup (0)
  19.  
  20. dseg        ends
  21.  
  22.  
  23. cseg        segment    para public 'code'
  24.         assume    cs:cseg, ds:dseg
  25.  
  26. Main        proc
  27.         mov    ax, dseg
  28.         mov    ds, ax
  29.         mov    es, ax
  30.         meminit
  31.  
  32.  
  33. ; MOVSB version done here:
  34.  
  35.         print
  36.         byte    "The following code moves a block of 16,384 bytes "
  37.         byte    "around 12,500 times.",cr,lf
  38.         byte    "The first phase does this using the movsb "
  39.         byte    "instruction; the second",cr,lf
  40.         byte    "phase does this using the lods/stos instructions; "
  41.         byte    "the third phase does",cr,lf
  42.         byte    "this using a loop with MOV instructions.",cr,lf,lf,lf
  43.         byte    "Press any key to begin phase one:",0
  44.  
  45.         getc
  46.         putcr
  47.  
  48.         mov    edx, 12500
  49.  
  50. movsbLp:    lea    si, Buffer1
  51.         lea    di, Buffer2
  52.         cld
  53.         mov    cx, 16384
  54.     rep    movsb
  55.         dec    edx
  56.         jnz    movsbLp
  57.  
  58.         print
  59.         byte    cr,lf
  60.         byte    "Phase one complete",cr,lf,lf
  61.         byte    "Press any key to begin phase two:",0
  62.  
  63.         getc
  64.         putcr
  65.  
  66.         mov    edx, 12500
  67.  
  68. LodsStosLp:    lea    si, Buffer1
  69.         lea    di, Buffer2
  70.         cld
  71.         mov    cx, 16384
  72. lodsstoslp2:    lodsb
  73.         stosb
  74.         loop    LodsStosLp2
  75.         dec    edx
  76.         jnz    LodsStosLp
  77.  
  78.         print
  79.         byte    cr,lf
  80.         byte    "Phase two complete",cr,lf,lf
  81.         byte    "Press any key to begin phase three:",0
  82.  
  83.         getc
  84.         putcr
  85.  
  86.         mov    edx, 12500
  87.  
  88. MovLp:        lea    si, Buffer1
  89.         lea    di, Buffer2
  90.         cld
  91.         mov    cx, 16384
  92. MovLp2:        mov    al, ds:[si]
  93.         mov    es:[di], al
  94.         inc    si
  95.         inc    di
  96.         loop    MovLp2
  97.         dec    edx
  98.         jnz    MovLp
  99.  
  100.  
  101. Quit:        ExitPgm            ;DOS macro to quit program.
  102. Main        endp
  103.  
  104. cseg        ends
  105.  
  106. sseg        segment    para stack 'stack'
  107. stk        db    1024 dup ("stack   ")
  108. sseg        ends
  109.  
  110. zzzzzzseg    segment    para public 'zzzzzz'
  111. LastBytes    db    16 dup (?)
  112. zzzzzzseg    ends
  113.         end    Main
  114.